<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="__STATIC__/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="__STATIC__/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="__STATIC__/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="__STATIC__/Admin/Flat/img/favicon.ico">
	    <script type="text/javascript" src="__STATIC__/uploadify/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>	
	    <link href="__STATIC__/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/ueditor.config.js"></script>
	    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/ueditor.all.min.js"></script>
	    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	    <script type="text/javascript">
	    	var getAttrURL='{|U:"AjaxGetAttr"}';
	    	var cid={$goodsData.category_cid};
	    	var bid={$goodsData.brand_bid};
	    </script>
	    <script src="__STATIC__/Admin/js/goods.js" type="text/javascript" charset="utf-8"></script>
	    <script src="__STATIC__/Admin/js/editgoods.js" type="text/javascript" charset="utf-8"></script>
	    <style type="text/css">
	    	.addPrice{
	    		text-align: right;
	    	}
	    	.imgList ul li{
	    		list-style: none;
	    		float:left;
	    	}
	    	.imgList img{
	    		margin-right: 30px;
	    		margin-bottom: 20px;
	    	}
	    </style>
	</head>
	<body>
		<form action="" method="post">
		<div class="alert alert-success">编辑商品</div>
		<!-- 基本信息 -->
		<table class="table table-hover">
			<tr class="active">
			  <th width="150">基本信息</th>
			  <th></th>
			  <th width="450"></th>
			</tr>
			<tr>
				<td style="line-height:40px">商品名称</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="gname" value="{$goodsData.gname}" id="" class="form-control" type="text" placeholder="请输入商品名称" required="" >
				</td>
				<td></td>
			</tr>
			<tr >
				<td style="line-height:40px">所属分类</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<select name="category_cid" id='category' class="form-control">
						<!--<option value="{$goodsData.category_cid}" checked tpid={$goodsData.tpid}>{$goodsData.cname}</option>-->
						<option value="0">请选择</option>
						<foreach from="$cateData" key="$k" value="$c">
							<option value="{$c.cid}" tpid='{$c.tpid}'>{$c._name}</option>
						</foreach>
					</select>
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">所属品牌</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<select name="brand_bid" id="brand" class="form-control">
						<option value="0">请选择</option>
						<foreach from="$brandData" key="$k" value="$b"> 
							<option value="{$b.bid}">{$b.bname}</option>
						</foreach>	
					</select>
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">商品标号</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="gnum"  value="{$goodsData.gnum}" class="form-control" type="text" placeholder="请输入商品标号： " required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">单位</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="unit" value="{$goodsData.unit}" class="form-control" type="text" placeholder="请输入单位名称： 如 ( 件 ) " required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">市价场</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="market_price" value="{$goodsData.market_price}" class="form-control" type="text" placeholder="请输入市价场" required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">商城价</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="shop_price" value="{$goodsData.shop_price}" class="form-control" type="text" placeholder="请输入商城价" required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">点击量</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="click_num" value="{$goodsData.click_num}" class="form-control" type="text" placeholder="商品点击量" required="">
				</td>
				<td></td>
			</tr>
		</table>
		<!-- 商品属性 -->
		<table id="goodsAttr" class="table table-hover">
			<tr class="active">
			   <th width="150">商品属性</th>
			   <th></th>
			   <th width="450"></th>
			</tr>
			<foreach from="$attr" key="$k" value="$a">
				<tr>
					<td style="line-height:40px">{$a.tp_aname}</td>
					<td>
						<select name="attr[{$a.tp_aid}]" class="form-control">
							<option value="0">请选择</option>
							<foreach from="$a['tp_avalue']" key="$kk" value="$av">
								<option value="{$av}" <if value="in_array($av,$goodsAttr)">selected</if>>{$av}</option>
							</foreach>
						</select>
					</td>
					<td></td>
				</tr>
			</foreach>
		</table>
		<!-- 商品规格 -->
		<table id="goodsSpec" class="table table-hover">
			<tr class="active">
			  <th width="80">商品规格</th>
			  <th width="200"></th>
			  <th width="80"></th>
			  <th width="100"></th>
			  <th width="30"></th>
			</tr>
			<foreach from="$spec" key="$k" value="$s">
				<!--判断属性表中的属性值是空还是数组，输出不同的表单-->
				<if value="$s['tp_avalue']==''">
				<!--单行文本添加式-->
					<!--循环出旧的数据-->
					<if value="isset($goodsSpec[$s['tp_aid']])">
						<?php $time=1; ?>
						<foreach from="$goodsSpec[$s['tp_aid']]" key="$gk" value="$gs">
							<tr class="attrList">
								<td style="line-height:40px">{$s.tp_aname}</td>
								<td>
									<input name="spec[{$s.tp_aid}][]" value="{$gs.attr_value}" class="form-control" placeholder="请输入{$s.tp_aname}" type="text">
								</td>
								<td class="addPrice" style="line-height:40px;">附加价格</td>
								<td>
									<input class="form-control" placeholder="请输入附加价格" name="addPrice[{$s.tp_aid}][]" value="{$gs.subjoin}" type="text">
								</td>
								<td>
									<if value="$time==1">
										<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
									<else/>
										<a href="javascript:;" class="btn btn-danger removeSpec">删除规格 </a>
									</if>
									<?php $time++; ?>
								</td>
							</tr>
						</foreach>
					<else/>
						<tr class="attrList">
							<td style="line-height:40px">{$s.tp_aname}</td>
							<td>
								<input name="spec[{$s.tp_aid}][]" value="" class="form-control" placeholder="请输入{$s.tp_aname}" type="text">
							</td>
							<td class="addPrice" style="line-height:40px;">附加价格</td>
							<td>
								<input class="form-control" placeholder="请输入附加价格" name="addPrice[{$s.tp_aid}][]" value="0" type="text">
							</td>
							<td>
								<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
							</td>
						</tr>
					</if>
				<!--下拉菜单式-->
				<elseif value="is_array($s)"/>
					<!--循环出旧的数据-->
					<if value="isset($goodsSpec[$s['tp_aid']])">
						<?php $time=1; ?>
						<foreach from="$goodsSpec[$s['tp_aid']]" key="$gk" value="$gs">
							<tr class="attrList">
								<td style="line-height:40px">{$s.tp_aname}</td>
								<td>
									<select name="spec[{$s.tp_aid}][]" class="form-control">
										<option value="0">请选择</option>
										<foreach from="$s[tp_avalue]" key="$kk" value="$av">
											<option <if value="$av==$gs['attr_value']" >selected</if> value="{$av}">{$av}</option>
										</foreach>
									</select>
								</td>
								<td class="addPrice" style="line-height:40px;">附加价格</td>
								<td>
									<input class="form-control" placeholder="请输入附加价格" name="addPrice[{$s.tp_aid}][]" value="{$gs['subjoin']}" type="text">
								</td>
								<td>
									<if value="$time==1">
										<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
									<else/>
										<a href="javascript:;" class="btn btn-danger removeSpec">删除规格 </a>
									</if>
									<?php $time++; ?>
								</td>
							</tr>
						</foreach>
					<else/>
						<tr class="attrList">
							<td style="line-height:40px">{$s.tp_aname}</td>
							<td>
								<select name="spec[{$s.tp_aid}][]" class="form-control">
									<option value="0">请选择</option>
									<foreach from="$s[tp_avalue]" key="$kk" value="$av">
										<option value="{$av}">{$av}</option>
									</foreach>
								</select>
							</td>
							<td class="addPrice" style="line-height:40px;">附加价格</td>
							<td>
								<input class="form-control" placeholder="请输入附加价格" name="addPrice[{$s.tp_aid}][]" value="0" type="text">
							</td>
							<td>
								<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
							</td>
						</tr>
					</if>
				</if>
			</foreach>
		</table>
		<!-- 列表图 -->
		<table class="table table-hover">
			<tr class="active">
				<th width="110">列表图</th>
				<th width="300"></th>
				<th width="600"></th>
			</tr>
			<tr>
				<td style="line-height:40px">上传列表图</td>
				<td>
					<input id="list_img_btn" class="upbtn" type="file" multiple="false">
					<label for="">类型: *.jpg,*.png 大小: 2000KB</label>
				</td>
				<td>
	            	<div id="listImgList" class="imgList"><ul>
	            		<if value="$goodsData['list_img']">
		            		<li>
		            			<img src="__ROOT__/{$goodsData.list_img}" alt="" style="width:200px;height:100px;" />
		            	 		<input type="hidden" name="list_img" value="{$goodsData.list_img}" />
		            		</li>
	            		</if>
	            	</ul></div>
				</td>
			</tr>
		</table>
		<!-- 商品图册 -->
		<table class="table table-hover">
			<tr class="active">
			  <th width="110">商品图册</th>
				<th width="300"></th>
				<th width="600"></th>
			</tr>
			<tr>
				<td style="line-height:40px">上传商品图册</td>
				<td>
					<input id="showImg_btn" class="upbtn" type="file" multiple="true">
					<label for="">类型: *.jpg,*.png 大小: 2000KB</label>
				</td>
				<td>
	            	 <div id="showImgList" class="imgList"><ul>
	            	 	<foreach from="$goodsData['bimg']" key="$k" value="$v">
	            	 		<li>
		            	 		<img src="__ROOT__/{$v}" alt="" style="width:200px;height:100px;" />
		            	 		<input type="hidden" name="showImg[]" value="{$v}" />
	            	 		</li>
	            	 	</foreach>
	            	 </ul></div>
				</td>
			</tr>
		</table>
		<!-- 商品详细 -->
		<table class="table table-hover">
			<tr class="active">
			  <th class="goodsDetails">商品详细</th>
			</tr>
			<tr class="bdtext">
				<td>
					<script id="editor" type="text/plain" name="info" style="width:1024px;height:500px;">{$goodsData.info}</script>
	   				 <script>
	       				 var ue = UE.getEditor('editor');
	   				 </script>
				</td>
			</tr>
		</table>
		<!-- 售后服务 -->
		<!--<table class="table table-hover">
			<tr class="active">
			  <th >售后服务</th>
			</tr>
			<tr>
				<td style="line-height:40px">百度编辑器</td>
			</tr>
		</table>-->
		<input type="hidden" name="gid" value="{$hd.get.gid}" />
		<input class="btn btn-primary btn-block" type="submit" value="确定修改">
		</form>
		
		<!--商品列表图上传-->
		<div lab="uploadFile">
	        <script type="text/javascript">
	            $(function() {
	                $('#list_img_btn').uploadify({
	                    'formData'     : {//POST数据
	                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                    },
	                    'fileTypeDesc' : '上传文件',//上传描述
	                    'fileTypeExts' : '{$set['filetype']}',
	                    'swf'      : '__STATIC__/uploadify/uploadify.swf',
	                    'uploader' : '{|U:"listImg"}',
	                    'buttonText':'选择文件',
	                    'fileSizeLimit' : '2000KB',
	                    'uploadLimit' : 1,//上传文件数
	                    'width':65,
	                    'height':25,
	                    'successTimeout':10,//等待服务器响应时间
	                    'removeTimeout' : 0.2,//成功显示时间
	                    'onUploadSuccess' : function(file, data, response) {
	                        data=$.parseJSON(data);
	                        var imageUrl = data.image?data.url:'__STATIC__/image/default.png';
	                        var li="<li><img src='"+imageUrl+"' style='width:200px;height:100px;'/>"+
	                      		  "<input type='hidden' name='list_img' value='"+data.path+"'/> </li>";
	                        $("#listImgList ul").prepend(li);
	                        $('#list_img_btn').slideUp().siblings('label').slideUp();
	                    }
	                });
//	                alert($("#listImgList ul").find('img').length!=0);
	                if($("#listImgList ul").find('img').length!=0){
	                	$('#list_img_btn').css({"display":"none"}).siblings().css({"display":"none"})
	                };
	            });
	           
	        </script>
		</div>
		<!--商品图册上传-->
		<div lab="uploadFile">
	        <script type="text/javascript">
	            $(function() {
	                $('#showImg_btn').uploadify({
	                    'formData'     : {//POST数据
	                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                    },
	                    'fileTypeDesc' : '上传文件',//上传描述
	                    'fileTypeExts' : '{$set['filetype']}',
	                    'swf'      : '__STATIC__/uploadify/uploadify.swf',
	                    'uploader' : '{|U:"showImg"}',
	                    'buttonText':'选择文件',
	                    'fileSizeLimit' : '2000KB',
	                    'uploadLimit' : 10,//上传文件数
	                    'width':65,
	                    'height':25,
	                    'successTimeout':10,//等待服务器响应时间
	                    'removeTimeout' : 0.2,//成功显示时间
	                    'onUploadSuccess' : function(file, data, response) {
	                        data=$.parseJSON(data);
	                        var imageUrl = data.image?data.url:'__STATIC__/image/default.png';
	                        var li="<li><img src='"+imageUrl+"' style='width:200px;height:100px;'/>"+
	                      		  "<input type='hidden' name='showImg[]' value='"+data.path+"'/> </li>";
	                        $("#showImgList ul").prepend(li);
	                    }
	                });
	            });
	        </script>
		</div>
	
	</body>
</html>
